﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using Microsoft.VisualBasic.Logging;
using System.Configuration;

namespace CurriculumnManage.Helper
{
    public class MyLog
    {
        private static TraceSource ts;
        public static TraceSource TraceInstance
        {
            get
            {
                if (ts == null)
                    InitTs();
                return ts;
            }
        }
        private static void InitTs()
        {
            ts = new TraceSource("DefaultSource");
            ts.Switch.Level = SourceLevels.All;
            FileLogTraceListener listener = null;
            foreach (TraceListener item in ts.Listeners)
            {
                if (item is FileLogTraceListener)
                {
                    listener = (FileLogTraceListener)item;
                    break;
                }
            }

            if (listener != null)
            {
                listener.Location = LogFileLocation.Custom;
                listener.CustomLocation = ConfigurationManager.AppSettings["logFilePath"];
                listener.BaseFileName = "webCurriculumn";
                listener.LogFileCreationSchedule = LogFileCreationScheduleOption.Daily;
                listener.Append = true;
                listener.Delimiter = "|";
                
                listener.AutoFlush = true;
            };
        }
    }
}
